require 'default.rb'
require 'defaultMappingRegistry.rb'
require 'soap/rpc/driver'

class Soap < ::SOAP::RPC::Driver
  DefaultEndpointUrl = "https://webservice.exacttarget.com/Service.asmx"

  Methods = [
    [ "Create",
      "create",
      [ ["in", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "CreateRequest"]],
        ["out", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "CreateResponse"]] ],
      { :request_style =>  :document, :request_use =>  :literal,
        :response_style => :document, :response_use => :literal,
        :faults => {} }
    ],
    [ "Retrieve",
      "retrieve",
      [ ["in", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "RetrieveRequestMsg"]],
        ["out", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "RetrieveResponseMsg"]] ],
      { :request_style =>  :document, :request_use =>  :literal,
        :response_style => :document, :response_use => :literal,
        :faults => {} }
    ],
    [ "Update",
      "update",
      [ ["in", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "UpdateRequest"]],
        ["out", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "UpdateResponse"]] ],
      { :request_style =>  :document, :request_use =>  :literal,
        :response_style => :document, :response_use => :literal,
        :faults => {} }
    ],
    [ "Delete",
      "delete",
      [ ["in", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "DeleteRequest"]],
        ["out", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "DeleteResponse"]] ],
      { :request_style =>  :document, :request_use =>  :literal,
        :response_style => :document, :response_use => :literal,
        :faults => {} }
    ],
    [ "Query",
      "query",
      [ ["in", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "QueryRequestMsg"]],
        ["out", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "QueryResponseMsg"]] ],
      { :request_style =>  :document, :request_use =>  :literal,
        :response_style => :document, :response_use => :literal,
        :faults => {} }
    ],
    [ "Describe",
      "describe",
      [ ["in", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "DefinitionRequestMsg"]],
        ["out", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "DefinitionResponseMsg"]] ],
      { :request_style =>  :document, :request_use =>  :literal,
        :response_style => :document, :response_use => :literal,
        :faults => {} }
    ],
    [ "Execute",
      "execute",
      [ ["in", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "ExecuteRequestMsg"]],
        ["out", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "ExecuteResponseMsg"]] ],
      { :request_style =>  :document, :request_use =>  :literal,
        :response_style => :document, :response_use => :literal,
        :faults => {} }
    ],
    [ "Perform",
      "perform",
      [ ["in", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "PerformRequestMsg"]],
        ["out", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "PerformResponseMsg"]] ],
      { :request_style =>  :document, :request_use =>  :literal,
        :response_style => :document, :response_use => :literal,
        :faults => {} }
    ],
    [ "Configure",
      "configure",
      [ ["in", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "ConfigureRequestMsg"]],
        ["out", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "ConfigureResponseMsg"]] ],
      { :request_style =>  :document, :request_use =>  :literal,
        :response_style => :document, :response_use => :literal,
        :faults => {} }
    ],
    [ "Schedule",
      "schedule",
      [ ["in", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "ScheduleRequestMsg"]],
        ["out", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "ScheduleResponseMsg"]] ],
      { :request_style =>  :document, :request_use =>  :literal,
        :response_style => :document, :response_use => :literal,
        :faults => {} }
    ],
    [ "VersionInfo",
      "versionInfo",
      [ ["in", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "VersionInfoRequestMsg"]],
        ["out", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "VersionInfoResponseMsg"]] ],
      { :request_style =>  :document, :request_use =>  :literal,
        :response_style => :document, :response_use => :literal,
        :faults => {} }
    ],
    [ "Extract",
      "extract",
      [ ["in", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "ExtractRequestMsg"]],
        ["out", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "ExtractResponseMsg"]] ],
      { :request_style =>  :document, :request_use =>  :literal,
        :response_style => :document, :response_use => :literal,
        :faults => {} }
    ],
    [ "GetSystemStatus",
      "getSystemStatus",
      [ ["in", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "SystemStatusRequestMsg"]],
        ["out", "parameters", ["::SOAP::SOAPElement", "http://exacttarget.com/wsdl/partnerAPI", "SystemStatusResponseMsg"]] ],
      { :request_style =>  :document, :request_use =>  :literal,
        :response_style => :document, :response_use => :literal,
        :faults => {} }
    ]
  ]

  def initialize(endpoint_url = nil)
    endpoint_url ||= DefaultEndpointUrl
    super(endpoint_url, nil)
    self.mapping_registry = DefaultMappingRegistry::EncodedRegistry
    self.literal_mapping_registry = DefaultMappingRegistry::LiteralRegistry
    init_methods
  end

private

  def init_methods
    Methods.each do |definitions|
      opt = definitions.last
      if opt[:request_style] == :document
        add_document_operation(*definitions)
      else
        add_rpc_operation(*definitions)
        qname = definitions[0]
        name = definitions[2]
        if qname.name != name and qname.name.capitalize == name.capitalize
          ::SOAP::Mapping.define_singleton_method(self, qname.name) do |*arg|
            __send__(name, *arg)
          end
        end
      end
    end
  end
end

